#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;
using PSI = pair<string, int>;

const int N = 1e5 + 10;

int n, m;
PSI op[N];

using namespace std;


int calc(int bit, int now){
    for(int i = 1; i <= n; i ++){
        int x = (op[i].second >> bit) & 1;
        if(op[i].first == "AND") now &= x;
        else if(op[i].first == "OR") now |= x;
        else now ^= x;
    }
    
    return now;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> m;
    
    for(int i = 1; i <= n; i ++){
        string temp;
        int x;
        cin >> temp >> x;
        op[i] = {temp, x};
    }
    

    
    int val = 0, res = 0;
    for(int bit = 29; bit >= 0; bit --){
        int res0 = calc(bit, 0);
        int res1 = calc(bit, 1);
        
        if(val + (1 << bit) <= m && res0 < res1){
            val += 1 << bit, res += res1 << bit;
        }else{
            res += res0 << bit;
        }
    }
    
    cout << res << '\n';
    
    return 0;
}